#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int maxn = 2e5 + 5;

ll d[maxn];
int v[maxn],a[maxn],det[maxn],L[maxn],R[maxn],num[maxn];

queue<pair<int,int>> Q;

int main() {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while (t--) {
        memset(num,0,sizeof(num));
        memset(L,0,sizeof(L));
        memset(R,0,sizeof(R));
        int n,m,D,V;
        cin >> n >> m >> D >> V;
        for (int i = 0; i < n; i++) {
            cin >> d[i] >> v[i] >> a[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> det[i];
        }
        sort(det,det + m);
        for (int i = 0; i < n; i++) {
            ll dis = 0LL;
            if (a[i] > 0) {
                if (v[i] > V) dis = d[i];
                else dis = (V*V - v[i]*v[i] + 2*a[i]-1) / (2 * a[i]) + d[i];
                if (dis >= det[m-1]) {
                    L[i] = -1;
                    R[i] = -1;
                } else {
                    for (int j = 0; j < m; j++) {
                        if (det[j] > dis) {
                            L[i] = j;
                            R[i] = m-1;
                            break;
                        }
                    }
                }
            } else if (a[i] < 0) {
                if (v[i] <= V) {
                    L[i] = -1;
                    R[i] = -1;
                } else {
                    //cout << i << " " << v[i] << " " << a[i] << endl;
                    ll dis = (V*V - v[i]*v[i] + 2*a[i]+ 1) / (2*a[i]) + d[i];
                    bool flag = false;
                    for (int j = 0; j < m; j++) {
                        if (d[i] <= det[j] && det[j] < dis) {
                            if (!flag) {
                                L[i] = j;
                                flag = true;
                            }
                            R[i] = j;
                        }
                    }
                    if (!flag) {
                        L[i] = -1;
                        R[i] = -1;
                    }
                }
            } else {
                if (v[i] <= V) {
                    L[i] = -1;
                    R[i] = -1;
                } else {
                    if (d[i] >= det[m-1]) {
                        L[i] = -1;
                        R[i] = -1;
                    } else {
                        for (int j = 0; j < m; j++) {
                            if (det[j] > d[i]) {
                                L[i] = j;
                                R[i] = m-1;
                                break;
                            }
                        }
                    }
                }
            }
        }
        int cnt = 0,ans = 0;
        for (int i = 0; i < n; i++) {
            //cout << L[i] << " " << R[i] << endl;
            if (L[i] != -1) {
                if (L[i] == R[i]) {
                    ans++;
                    num[L[i]] = -1;
                }
                //cout << i << endl;
                cnt++;
            }
        }
        for (int i = 0; i < n; i++) {
            bool fl = true;
            for (int j = L[i]; j <= R[i]; j++) {
                if (num[j] == -1) {
                    fl = false;
                }
            }
            if (fl) {
                Q.push(make_pair(L[i],R[i]));
                for (int j = L[i]; j <= R[i]; j++) {
                    num[j]++;
                }
            }
        }
        cout << cnt << " ";
        bool flag = false;
        while (!flag) {
            flag = true;
            for (int i = 0; i < n; i++) {
                if (num[i] > 0) {
                    flag = false;
                }
            }
            if (flag) break;
            int maxi = -1,maxnum = -1;
            for (int i = 0; i < n; i++) {
                if (num[i] > maxi) {
                    maxi = num[i];
                    maxnum = i;
                }
            }
            ans++;
            int ctn = 0;
            int len = Q.size();
            while (ctn != len) {
                ctn++;
                pair<int,int> k = Q.front();
                Q.pop();
                if (k.first <= maxnum && maxnum <= k.second) {
                    for (int i = k.first; i <= k.second; i++) {
                        num[i]--;
                    }
                } else {
                    Q.push(k);
                }
            }
        }
        cout << m-ans << endl;
    }
    return 0;
}
